<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');


$building_id = mysql_real_escape_string(strip_tags($_GET['id']));

$get_building_data = mysql_query("SELECT * FROM buildings WHERE id = $building_id");
$building_name = mysql_result($get_building_data,0,'building_name');
$abbreviation = mysql_result($get_building_data,0,'abbreviation');

?>
<p>
	<a href="../">&lt;&lt; Back to Buildings Portal</a>
</p>
<?php
echo "<h1>$building_name Classrooms</h1>";
echo '<p>';
//creates link/button for add classroom
echo "<a href='add.php?bid=$building_id'>Add Classroom OR Classroom Type</a>";
echo '</p>';

//select statement
$query="SELECT * FROM classrooms WHERE building_id = $building_id ORDER BY room_num";
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{

	//start table
	echo "<table class=\"postSchedule\">";
	
		//create table row with column ID's
		echo "<tr>";
			echo "<td><b>Room</b></td>";
			echo "<td><b>Type</b></td>";
			echo "<td style='text-align: center'><b>Seats</b></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td></td>";
		echo "</tr>";

	//loop to walk through and print to screen all entries in classrooms table
	$row_count = 0;
	while ($row = mysql_fetch_assoc($result)) 
	{
		$row_count++;
		//store each classroomname and abbreviation in a scalar
		$classroom_id=$row["id"];
		$room_num=$row["room_num"];
		$num_seats=$row["num_seats"];
		$classroom_type_id=$row["classroom_type_id"];

		$query2="SELECT * FROM classroom_types WHERE id = $classroom_type_id";
		$result2=mysql_query($query2);
		$row2 = mysql_fetch_assoc($result2);
		$type_description=$row2["description"];
	
		//generate table row for each classroomon each iteration of the loop
		echo "<tr";
		if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
		echo ">";
			echo "<td>$abbreviation $room_num</td>";		//classroomname cell
			echo "<td>$type_description</td>";		//classroomabbreviation cell
			echo "<td style='text-align: center'>$num_seats</td>";
			echo "<td>";		//cell containing form for edit classroomlink/button
				echo "<a href='edit.php?id=$classroom_id&amp;bid=$building_id'>Edit</a>";
			echo "</td>";
		
			echo "<td>";		//cell containing form for delete classroomlink/button
				echo "<a href='delete.php?id=$classroom_id&amp;bid=$building_id'>Delete</a>";
			echo "</td>";
			
			echo "<td>";		//cell containing form for closings link/button
				echo "<a href='closings/?id=$classroom_id&amp;bid=$building_id'>Classroom Closings</a>";
			echo "</td>";
	
		echo "</tr>";
		
	}

	//end table tag
	echo "</table>";

}
else
{
	echo "<p><b>NO CLASSROOMS CURRENTLY ASSIGNED TO BUILDING</b></p>";
}
?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>